Skip to content

feat(wallet): wire RemoteFeatureFlagController into default initialization#8969

Open
sirtimid wants to merge 3 commits into
mainfrom
sirtimid/wire-remote-feature-flag-controller
Open

feat(wallet): wire RemoteFeatureFlagController into default initialization#8969
sirtimid wants to merge 3 commits into
mainfrom
sirtimid/wire-remote-feature-flag-controller

Conversation

@sirtimid
Copy link
Copy Markdown
Member

@sirtimid sirtimid commented Jun 2, 2026

Explanation

This wires RemoteFeatureFlagController into @metamask/wallet's default controller initialization, so the wallet manages remote feature flags as part of its ensemble. It exposes the controller's standard messenger surface — RemoteFeatureFlagController:getState/:stateChange plus its method-actions (updateRemoteFeatureFlags, enable, disable, setFlagOverride, removeFlagOverride, clearAllFlagOverrides).

@metamask/wallet is the shared controller-integration layer for metamask-extension, metamask-mobile, and wallet-cli. The controller's constructor values that differ between those clients are therefore injectable via a new instanceOptions.remoteFeatureFlagController slot rather than hardcoded, each with a platform-agnostic default so a headless consumer can construct the wallet with no options at all. Values identical everywhere are not exposed.

The controller's messenger is a plain namespaced child with no delegation — the controller's own messenger type only allows its own actions/events, and both clients already construct it that way. The per-client orchestration that reads PreferencesController/OnboardingController (extension) or a basic-functionality selector (mobile) to enable/disable the controller is not part of the controller and is not delegated here: those sources aren't wallet controllers (mobile's isn't even a controller). Clients keep that orchestration in their own glue and drive it over the shared messenger via the exposed RemoteFeatureFlagController:enable/:disable actions; the wallet only takes the initial disabled value and a getMetaMetricsId callback as injectable options.

Note for the owning teams: when no clientConfigApiService is injected, the controller is wired with a network-free default that returns an empty flag set (so wallet-cli works headlessly). A client that intends to fetch flags but forgets to inject its service would therefore silently get zero flags rather than an error. Extension and mobile always inject a real ClientConfigApiService, so this only affects deliberately headless consumers — flagging it so the choice of "optional with inert default" vs. "required" is a conscious one. This mirrors the ApprovalController slot's no-op default.

Per-environment options

Option Extension Mobile Default (e.g. wallet-cli)
clientConfigApiService new ClientConfigApiService({ fetch, config: { client: Extension, distribution, environment } }) new ClientConfigApiService({ fetch, config: { client: Mobile, environment, distribution } }) network-free service that returns no flags
getMetaMetricsId () => MetaMetricsController:getMetaMetricsId () => analyticsId () => ''
clientVersion getBaseSemVerVersion() getBaseSemVerVersion() '0.0.0'
prevClientVersion persistedState.AppMetadataController.currentAppVersion persistedState.AppMetadataController.currentAppVersion undefined
fetchInterval 15 * 60 * 1000 __DEV__ ? 1000 : DEFAULT_FETCH_INTERVAL controller default (1 day)
disabled !completedOnboarding || !useExternalServices !selectBasicFunctionalityEnabled(state) controller default (false)

The dynamic enable/disable toggling (subscribing to the sources above and calling enable/disable) stays client-side; only the initial disabled value is an option here.

References

Current client construction sites (live main):

Closes #8794.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes (N/A — additive)

🤖 Generated with Claude Code


Note

Medium Risk
Touches shared wallet bootstrap and remote flag fetching; misconfigured clients could silently see no flags, and duplicate controller wiring elsewhere could still collide like other default controllers.

Overview
Adds RemoteFeatureFlagController to @metamask/wallet’s default initialization so extension, mobile, and wallet-cli get remote feature flags through the shared wallet messenger (getState, updateRemoteFeatureFlags, etc.).

A new instanceOptions.remoteFeatureFlagController slot forwards platform-specific settings (clientConfigApiService, getMetaMetricsId, clientVersion, prevClientVersion, fetchInterval, disabled) with headless-safe defaults (no-op fetch, empty metrics id, '0.0.0' semver). Clients that omit a real config API service get an empty flag set without failing.

Also adds the @metamask/remote-feature-flag-controller dependency, exports the init config from the instances barrel, CODEOWNERS for the init folder, README dependency graph update, and unit/integration tests for defaults, injection, cache invalidation on version change, and wallet-level wiring.

Reviewed by Cursor Bugbot for commit 3989ae5. Bugbot is set up for automated code reviews on this repo. Configure here.

sirtimid added a commit that referenced this pull request Jun 2, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sirtimid sirtimid marked this pull request as ready for review June 2, 2026 12:01
@sirtimid sirtimid requested a review from a team as a code owner June 2, 2026 12:01
@sirtimid sirtimid temporarily deployed to default-branch June 2, 2026 12:01 — with GitHub Actions Inactive
@sirtimid sirtimid requested review from a team and FrederikBolding June 2, 2026 15:14
sirtimid added a commit that referenced this pull request Jun 8, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sirtimid sirtimid force-pushed the sirtimid/wire-remote-feature-flag-controller branch from c704d42 to 6e59aee Compare June 8, 2026 12:03
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Jun 8, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

sirtimid added a commit that referenced this pull request Jun 8, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sirtimid sirtimid force-pushed the sirtimid/wire-remote-feature-flag-controller branch from 6e59aee to 6ea8b4d Compare June 8, 2026 12:04
@sirtimid
Copy link
Copy Markdown
Member Author

sirtimid commented Jun 8, 2026

@metamaskbot publish-previews

@sirtimid
Copy link
Copy Markdown
Member Author

sirtimid commented Jun 8, 2026

@SocketSecurity ignore npm/@metamask/remote-feature-flag-controller@4.2.2

sirtimid added a commit that referenced this pull request Jun 8, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sirtimid sirtimid force-pushed the sirtimid/wire-remote-feature-flag-controller branch from 6ea8b4d to ae15713 Compare June 8, 2026 12:18
sirtimid and others added 3 commits June 8, 2026 14:03
…ization

Adds `RemoteFeatureFlagController` to the wallet's default controller
ensemble, exposing per-platform constructor values through a new
`instanceOptions.remoteFeatureFlagController` slot: `clientConfigApiService`,
`getMetaMetricsId`, `clientVersion`, `prevClientVersion`, `fetchInterval`,
and `disabled`. Each is injectable with an inert/neutral default so the
controller is usable headlessly; extension and mobile inject their own
values. The controller's messenger is a plain namespaced child with no
delegation.

`prevClientVersion` lets consumers trigger feature-flag cache invalidation
when the client version changes between sessions.

Closes #8794

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tureFlagController

Migrates the RemoteFeatureFlagController instance to the per-controller
directory convention (introduced by #8953, extended by #8977):
`instances/remote-feature-flag-controller/` now holds the config, the
colocated test, and a `RemoteFeatureFlagControllerInstanceOptions` type in
its own `types.ts`. `InstanceSpecificOptions` references that type instead of
an inline shape, and `instances/index.ts` + the CODEOWNERS `## Initialization`
entry use the directory form. No public exports or option shapes change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sirtimid sirtimid force-pushed the sirtimid/wire-remote-feature-flag-controller branch from ae15713 to 3989ae5 Compare June 8, 2026 13:05
@sirtimid
Copy link
Copy Markdown
Member Author

sirtimid commented Jun 8, 2026

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 8, 2026

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.1-preview-3989ae5
@metamask-previews/accounts-controller@39.0.0-preview-3989ae5
@metamask-previews/address-book-controller@7.1.2-preview-3989ae5
@metamask-previews/ai-controllers@0.7.0-preview-3989ae5
@metamask-previews/analytics-controller@1.1.1-preview-3989ae5
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-3989ae5
@metamask-previews/announcement-controller@8.1.0-preview-3989ae5
@metamask-previews/app-metadata-controller@2.0.1-preview-3989ae5
@metamask-previews/approval-controller@9.0.1-preview-3989ae5
@metamask-previews/assets-controller@8.3.2-preview-3989ae5
@metamask-previews/assets-controllers@108.5.0-preview-3989ae5
@metamask-previews/authenticated-user-storage@2.0.0-preview-3989ae5
@metamask-previews/base-controller@9.1.0-preview-3989ae5
@metamask-previews/base-data-service@0.1.3-preview-3989ae5
@metamask-previews/bridge-controller@73.2.1-preview-3989ae5
@metamask-previews/bridge-status-controller@72.0.2-preview-3989ae5
@metamask-previews/build-utils@3.0.4-preview-3989ae5
@metamask-previews/chain-agnostic-permission@1.6.1-preview-3989ae5
@metamask-previews/chomp-api-service@3.1.0-preview-3989ae5
@metamask-previews/claims-controller@0.5.2-preview-3989ae5
@metamask-previews/client-controller@1.0.1-preview-3989ae5
@metamask-previews/compliance-controller@2.1.0-preview-3989ae5
@metamask-previews/composable-controller@12.0.1-preview-3989ae5
@metamask-previews/config-registry-controller@0.4.0-preview-3989ae5
@metamask-previews/connectivity-controller@0.2.0-preview-3989ae5
@metamask-previews/controller-utils@12.1.0-preview-3989ae5
@metamask-previews/core-backend@6.3.2-preview-3989ae5
@metamask-previews/delegation-controller@3.0.1-preview-3989ae5
@metamask-previews/earn-controller@12.2.0-preview-3989ae5
@metamask-previews/eip-5792-middleware@3.0.4-preview-3989ae5
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-3989ae5
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-3989ae5
@metamask-previews/ens-controller@19.1.3-preview-3989ae5
@metamask-previews/eth-block-tracker@15.0.1-preview-3989ae5
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-3989ae5
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-3989ae5
@metamask-previews/foundryup@1.0.1-preview-3989ae5
@metamask-previews/gas-fee-controller@26.2.2-preview-3989ae5
@metamask-previews/gator-permissions-controller@4.2.0-preview-3989ae5
@metamask-previews/geolocation-controller@0.1.3-preview-3989ae5
@metamask-previews/json-rpc-engine@10.5.0-preview-3989ae5
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-3989ae5
@metamask-previews/keyring-controller@26.0.0-preview-3989ae5
@metamask-previews/logging-controller@8.0.2-preview-3989ae5
@metamask-previews/message-manager@14.1.2-preview-3989ae5
@metamask-previews/messenger@1.2.0-preview-3989ae5
@metamask-previews/messenger-cli@0.2.0-preview-3989ae5
@metamask-previews/money-account-balance-service@1.0.2-preview-3989ae5
@metamask-previews/money-account-controller@0.3.2-preview-3989ae5
@metamask-previews/money-account-upgrade-controller@2.0.3-preview-3989ae5
@metamask-previews/multichain-account-service@10.0.2-preview-3989ae5
@metamask-previews/multichain-api-middleware@3.1.3-preview-3989ae5
@metamask-previews/multichain-network-controller@3.1.3-preview-3989ae5
@metamask-previews/multichain-transactions-controller@7.1.1-preview-3989ae5
@metamask-previews/name-controller@9.1.2-preview-3989ae5
@metamask-previews/network-controller@32.0.0-preview-3989ae5
@metamask-previews/network-enablement-controller@5.3.0-preview-3989ae5
@metamask-previews/notification-services-controller@24.1.2-preview-3989ae5
@metamask-previews/passkey-controller@2.0.1-preview-3989ae5
@metamask-previews/permission-controller@13.1.1-preview-3989ae5
@metamask-previews/permission-log-controller@5.1.0-preview-3989ae5
@metamask-previews/perps-controller@7.0.0-preview-3989ae5
@metamask-previews/phishing-controller@17.2.0-preview-3989ae5
@metamask-previews/polling-controller@16.0.6-preview-3989ae5
@metamask-previews/preferences-controller@23.1.0-preview-3989ae5
@metamask-previews/profile-metrics-controller@3.1.6-preview-3989ae5
@metamask-previews/profile-sync-controller@28.1.1-preview-3989ae5
@metamask-previews/ramps-controller@14.1.1-preview-3989ae5
@metamask-previews/rate-limit-controller@7.0.1-preview-3989ae5
@metamask-previews/react-data-query@0.2.1-preview-3989ae5
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-3989ae5
@metamask-previews/sample-controllers@5.0.1-preview-3989ae5
@metamask-previews/seedless-onboarding-controller@10.0.0-preview-3989ae5
@metamask-previews/selected-network-controller@26.1.3-preview-3989ae5
@metamask-previews/shield-controller@5.1.2-preview-3989ae5
@metamask-previews/signature-controller@39.2.4-preview-3989ae5
@metamask-previews/snap-account-service@0.3.0-preview-3989ae5
@metamask-previews/social-controllers@2.2.1-preview-3989ae5
@metamask-previews/storage-service@1.0.1-preview-3989ae5
@metamask-previews/subscription-controller@6.1.3-preview-3989ae5
@metamask-previews/transaction-controller@67.0.0-preview-3989ae5
@metamask-previews/transaction-pay-controller@23.2.0-preview-3989ae5
@metamask-previews/user-operation-controller@41.2.3-preview-3989ae5
@metamask-previews/wallet@2.0.0-preview-3989ae5

sirtimid added a commit to MetaMask/metamask-extension that referenced this pull request Jun 8, 2026
…r [REVERT BEFORE MERGE]

TEMPORARY, testing-only. Bumps the `@metamask/wallet` npm alias from the
ApprovalController preview (`2.0.0-preview-ecd6b75`) to
`2.0.0-preview-3989ae5`, which additionally wires `RemoteFeatureFlagController`
(MetaMask/core#8969), so this draft PR can exercise CI against the real wiring
before a `@metamask/wallet` release exists.

Also adds the `@metamask/remote-feature-flag-controller` edge to the
`@metamask/wallet` LavaMoat policy entries (the preview wallet now imports it).

Revert this commit and bump `@metamask/wallet` to the published release once it
includes #8969.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sirtimid added a commit to MetaMask/metamask-extension that referenced this pull request Jun 8, 2026
…r [REVERT BEFORE MERGE]

TEMPORARY, testing-only. Bumps the `@metamask/wallet` npm alias from the
ApprovalController preview (`2.0.0-preview-ecd6b75`) to
`2.0.0-preview-3989ae5`, which additionally wires `RemoteFeatureFlagController`
(MetaMask/core#8969), so this draft PR can exercise CI against the real wiring
before a `@metamask/wallet` release exists.

Also adds the `@metamask/remote-feature-flag-controller` edge to the
`@metamask/wallet` LavaMoat policy entries (the preview wallet now imports it).

Revert this commit and bump `@metamask/wallet` to the published release once it
includes #8969.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sirtimid added a commit to MetaMask/metamask-mobile that referenced this pull request Jun 8, 2026
Construct RemoteFeatureFlagController through @metamask/wallet instead of
mobile's local Engine controller-init wiring, mirroring the ApprovalController
migration on the base branch and the KeyringController (#30368) and
StorageService (#30922) precedents. This is the mobile counterpart to core PR
MetaMask/core#8969.

- Delete the local remote-feature-flag-controller init + messenger (and both
  tests). The remote-feature-flag-controller/ helper dir (getFeatureFlagApp*
  helpers + isRemoteFeatureFlagOverrideActivated) is kept and reused from the
  new wiring.
- Drop RemoteFeatureFlagController from the controller-init registry (Engine.ts),
  the MESSENGER_FACTORIES map (messengers/index.ts), and the
  MessengerClientsToInitialize union (types.ts). It is kept in the
  MessengerClients type, the background state map, its Actions/Events unions, and
  the BACKGROUND_STATE_CHANGE_EVENT_NAMES Redux-bridge list (the wallet-owned
  controller emits stateChange on the same root bus).
- Pass mobile's values through instanceOptions.remoteFeatureFlagController when
  constructing the Wallet (wallet-init/initialization.ts): clientConfigApiService
  (ClientType.Mobile + environment/distribution), getMetaMetricsId, clientVersion,
  prevClientVersion, fetchInterval, and the initial disabled value.
- Preserve the client-side startup orchestration the wallet does NOT perform:
  the disabled/override logging and the startup updateRemoteFeatureFlags() fetch
  now run in the Engine constructor after the instance is resolved.
- Resolve the instance via wallet.getInstance('RemoteFeatureFlagController') so
  RemoteFeatureFlagController:* consumers on the shared root messenger resolve
  the wallet-owned instance.
- Add Engine integration tests for the preserved startup orchestration
  (disabled -> log + skip fetch; success -> "Feature flags updated"; failure ->
  "Feature flags update failed:"), restoring the coverage of the deleted
  remote-feature-flag-controller-init test.

No functional changes.

CHANGELOG entry: null

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sirtimid added a commit to MetaMask/metamask-mobile that referenced this pull request Jun 8, 2026
Bumps the temporary npm-alias pin from the RFFC-free preview (ecd6b75) to the
4-controller preview (2.0.0-preview-3989ae5 = the core#8969 branch head), which
wires RemoteFeatureFlagController into @metamask/wallet's default initialization.
This is required for the RFFC migration in the previous commit to typecheck and
to avoid a "RemoteFeatureFlagController:getState already registered" collision
(the wallet now registers the controller mobile used to init locally).

Kept as a direct npm alias in package.json (not the previewBuilds plugin) — the
form that passes CI's immutable resolve. @metamask-previews/* is already
preapproved in .yarnrc.yml, so the npm minimal-age gate does not block the fresh
preview. `yarn install --immutable` exits 0 with no YN0028.

Still TEMPORARY / DO NOT MERGE — revert this and pin the real @metamask/wallet
release (the one including MetaMask/core#8969) before marking ready.

CHANGELOG entry: null

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wallet: Pass prevClientVersion to RemoteFeatureFlagController

1 participant